package db_model

import (
	"time"

	"gorm.io/gorm"
)

// User represents the users table structure
// Uses pointer types (*string, *time.Time) for nullable fields
type User struct {
	ID         string          `json:"id" gorm:"type:uuid;primaryKey;default:gen_random_uuid()"`
	Email      string          `json:"email" gorm:"size:500;uniqueIndex;not null"`
	Name       string          `json:"name" gorm:"size:500;uniqueIndex;not null"`
	Password   *string         `json:"-" gorm:"size:500"` // 改为指针类型，允许为空（OAuth用户）
	FirstName  *string         `json:"first_name,omitempty" gorm:"type:text"`
	LastName   *string         `json:"last_name,omitempty" gorm:"type:text"`
	VerifiedAt *time.Time      `json:"verified_at,omitempty" gorm:"type:timestamptz"`
	Image      *string         `json:"image,omitempty" gorm:"type:text"`
	Address    *string         `json:"address,omitempty" gorm:"type:text"`
	Region     *string         `json:"region,omitempty" gorm:"type:char(2)"`
	Mobile     *string         `json:"mobile,omitempty" gorm:"type:text;uniqueIndex"`
	Role       int16           `json:"role" gorm:"type:smallint;not null;default:1"`
	CreatedAt  time.Time       `json:"created_at" gorm:"type:timestamptz;not null;default:CURRENT_TIMESTAMP"`
	UpdatedAt  *time.Time      `json:"updated_at,omitempty" gorm:"type:timestamptz"`
	DeletedAt  *gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
	OAuthUsers []OAuthUser     `json:"oauth_users,omitempty" gorm:"foreignKey:UserID"`
}

// TableName specifies the table name
func (User) TableName() string {
	return "users"
}
